package algorithm.dac;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-06-06 15:53
 * @ Description :
 */
public class HanoiTower
{

    public static void main(String[] args)
    {
        hanoiTower(5,'A','B','C');
        System.out.println("count1 = " + count1);
        System.out.println("countOther = " + countOther);
        System.out.println("count = " + count);
    }

    static int count = 0;
    static int count1 = 0;
    static int countOther = 0;
    //盘子从 a 塔移动到 c 塔, 使用到 b 塔
    public static void hanoiTower(int numOfPlates, char a, char b, char c)
    {
        count++;
        if (numOfPlates == 1)
        {
            count1++;
            System.out.println("第1个盘从" + a + "->" + c);
        }
        else
        {
            //1. 把上面的盘 A->B
            hanoiTower(numOfPlates - 1,a,c,b);
            //2. 把最下面的盘 A->C
            countOther++;
            System.out.println("第" + numOfPlates + "个盘从" + a + "->" + c);
            //3. 把B塔的盘 B->C
            hanoiTower(numOfPlates - 1,b,a,c);
        }
    }
}
